#pragma once
#include <iostream>
#include <fstream>

class Util {
public:
    static bool WriteFile(const std::string &file_name, const std::string &content) {
        std::ofstream ofs(file_name);
        if (!ofs.is_open())
            return false;

        ofs.write(content.c_str(), content.size());
        ofs.close();

        return true;
    }

    static bool ReadFile(const std::string &file_name, std::string *content, bool keep = false) {
        content->clear();

        std::ifstream ifs(file_name);
        if (!ifs.is_open())
            return false;

        std::string line;
        //getline不保留行分隔符
        while (std::getline(ifs, line)) {
            *content += (line + (keep ? "\n" : ""));
        }
        ifs.close();

        return true;
    }
};